package com.tao.service;


import com.tao.dto.ExceptionResult;
import com.tao.dto.MyResult;
import com.tao.dto.PageResult;
import com.tao.dto.SuccessResult;
import com.tao.entity.Member;
import com.tao.entity.RegisterCode;
import com.tao.repository.MemberRepository;
import com.tao.repository.RegisterCodeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class RegisterCodeService {
    @Autowired
    private RegisterCodeRepository registerCodeRepository;


    public RegisterCode insert(RegisterCode registerCode) {
        RegisterCode save = registerCodeRepository.save(registerCode);
        return save;
    }

    public RegisterCode findById(Integer id) {
        RegisterCode registerCode = registerCodeRepository.findById(id).get();
        return registerCode;
    }

    public PageResult findAll(RegisterCode registerCode,Integer page, Integer size) {
        Page<RegisterCode> all = registerCodeRepository.findAll(Example.of(registerCode), PageRequest.of(page, size));
        return PageResult.PageResultBuild(all.getTotalElements(), all.getContent());
    }
    public void delete(Integer id){
        registerCodeRepository.deleteById(id);
    }




}
